/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DBTables;

import DBManager.*;
import java.sql.PreparedStatement;
import java.sql.Connection;
import java.sql.ParameterMetaData;
import java.sql.SQLException;

/**
 *Класс таблицы Message
 * @author Иван
 */
public class TMessage extends DataManager {

    public String Id_UserFK;
    public String Id_ObjectiveFK;
    public String Node;
    public String Link_on_resurs;
    public String Date_of_Create;

    public TMessage(Connection conn, String tableName) throws SQLException {
        super(conn, tableName);

        SelectPrepStatement = connection.prepareStatement("select * from " + TableName);
        InsertPrepStatement = connection.prepareStatement("insert into" + TableName + "(Id_User, Id_Objective, Node, Link_on_resurs, Date_of_Create) values (?,?,?,?,?)");
        UpdatePrepStatement = connection.prepareStatement("update " + TableName + " set (Id_User = ?, Id_Objective = ?, Node = ?, Link_on_resurs = ?, , Date_of_Create = ?) Where Id_Message = ?");
        DeletePrepStatement = connection.prepareStatement("delete from " + TableName + " where Id_Message = ?");
    }

    @Override
    public void SetValues(PreparedStatement prepareStatement) throws SQLException {

        ParameterMetaData metaData = prepareStatement.getParameterMetaData();
        int countParameters = metaData.getParameterCount();

        if (countParameters >= 5) // for insert prepared statement
        {
            prepareStatement.setString(1, Id_UserFK);
            prepareStatement.setString(2, Id_ObjectiveFK);
            prepareStatement.setString(3, Node);
            prepareStatement.setString(4, Link_on_resurs);
            prepareStatement.setString(5, Date_of_Create);
        }

        if ((countParameters == 6))// for update prepared statement
        {
            prepareStatement.setString(6, ID_Table);
        }

        if ((countParameters == 1))// for delete prepared statement
        {
            prepareStatement.setString(1, ID_Table);
        }
    }
}
